package  
{
	/**
	 * ...
	 * @author Boothe
	 */
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.FP;
	public class Player extends Entity
	{
		private var falltime:int;
		private var onground:Boolean;
		public static var Health:int = 100;
		
		
		[Embed(source = "assets/Player.png")]private const PLAYER:Class;
		public var PlayerGraphic:Spritemap = new Spritemap(PLAYER, 32, 44);
		public var noanimgraphic:Image = new Image(PLAYER);
		public function Player() 
		{
			setHitbox(32, 44);
			
			type = "player";
			PlayerGraphic.add("walkright", [0, 1, 2, 1], 7, true);
			PlayerGraphic.add("walkleft", [17, 16, 15, 16], 7, true);
			PlayerGraphic.add("standright", [2], 7, true);
			PlayerGraphic.add("standleft", [15], 7, true);
			PlayerGraphic.add("punchright", [3], 1, false);
			PlayerGraphic.add("punchleft", [14], 1, false);
			graphic = PlayerGraphic;
		}
		public var punch:Boolean = false;
		public var punchtimeout:int = 0;
		public var lastx:int=0;
		public var lasty:int = 0;
		public var lastdirection:String="right";
		override public function update():void 
		{
			if (Input.check(Key.DOWN)) {
				y += 3;
			}
			if (Input.check(Key.UP)) {
				y -= 3;
			}
			if (Input.check(Key.LEFT)) {
				x -= 3;
				PlayerGraphic.play("walkleft");
				lastdirection = "left";
			}
			if (Input.check(Key.RIGHT)) {
				x += 3;
				PlayerGraphic.play("walkright");
				lastdirection = "right";
				
			}
			if (Input.pressed(Key.X) && punchtimeout < 20) {
				
				if (lastdirection == "right") {
					x += 5;
					PlayerGraphic.play("punchright");
					punch = true;
				}else {
					
					x -= 5;
					PlayerGraphic.play("punchleft");
					punch = true;
						
				}
			}
			
			
			if (punch == true) {
				
				if (punchtimeout < 40) {
					if (punchtimeout < 20){
						if (lastdirection == "right") {
							x += 5;
							PlayerGraphic.play("punchright");
							punch = true;
						}else {
							x -= 5;
							PlayerGraphic.play("punchleft");	
						}
					
					}
					punchtimeout++;
						
				}else {
					punch = false;
					punchtimeout = 0;
				}
				
				
			}
		
			var b:Bullet = collide("bullet", x, y) as Bullet;
			if (b&&punch) {
				b.destroy();
			}
			
			if (x == lastx) {
				if (lastdirection == "right") {
					PlayerGraphic.play("standright");
				}else {
					PlayerGraphic.play("standleft");
				}
				
			}
			lastx = x;
			
			
		}
	}

}